package net.gagnat.android.trackit.service;

import java.util.List;

import net.gagnat.android.trackit.domain.LogEntry;
import android.content.Context;

public class TrackItRepository {

	private static TrackItRepository trackItRepository;

	private LogEntriesRepository logEntriesRepository;
	private LogTagsRepository logTagsRepository;

	private TrackItRepository(Context context) {
		logEntriesRepository = LogEntriesRepository.initialize(context);
		logTagsRepository = LogTagsRepository.initialize(context);
	}

	public static TrackItRepository getInstance(Context context) {
		if (trackItRepository == null) {
			trackItRepository = new TrackItRepository(context);
		}
		return trackItRepository;
	}

	public List<LogEntry> getLogEntries() {
		return logEntriesRepository.getLogEntries();
	}

	public Long saveLogEntry(LogEntry logEntry) {
		Long logEntryId = logEntriesRepository.saveLogEntry(logEntry);
		List<String> tags = logEntriesRepository.getLogEntry(logEntryId).getTags();
		logTagsRepository.updateTagList(tags);
		return logEntryId;
	}

}
